package org.ccay.core.orm.impl;

import javax.inject.Named;

import org.ccay.core.exception.IExceptionConverter;
import org.ccay.core.util.exception.TimeoutException;

/**
 * 转换BadSqlGrammarException，处理Timeout相关的异常
 * 
 * @since 2013年8月6日
 */
@Named("IExceptionConverter.org.springframework.jdbc.BadSqlGrammarException")
public class BadSqlGrammarExceptionConverter implements IExceptionConverter {

	private static final String ORACLE_TIMEOUT = "ORA-02049";

	/* (non-Javadoc)
	 * @see org.ccay.core.exception.IExceptionConverter#convert(java.lang.Throwable)
	 */
	public Throwable convert(Throwable originalException) {
		String message = originalException.getMessage();
		if(message.indexOf(ORACLE_TIMEOUT)!=-1){
			return new TimeoutException(originalException);
		}
		
		return originalException;		 
	}
}